Option Strict Off
Option Explicit On
Imports SlimDX
Module PubDx
	Public PCanvas As Object
	Public m_binit As Boolean
	Public m_FOGEnabled As Boolean
	Public m_FOGColor As Boolean
	Public m_Paused As Boolean
	
    Public d3ddm As Direct3D9.DisplayMode
	
	Structure m_RkLines
		Dim v1 As Vector3
		Dim v2 As Vector3
		Dim Color As Integer
	End Structure
	
	Structure Box
        Dim Min As Vector3
        Dim Max As Vector3
	End Structure
	
	Structure rColorScheme
		Dim Name As String
		Dim r As Double
		Dim g As Double
        Dim b As Double
        Public Function ToRGB() As Integer
            Return RGB(r, g, b)
        End Function
	End Structure
	
	Public ColorScheme() As rColorScheme
	Public TotalSchemes As Short
	
	
	Public UC As Object
    Public UT As Windows.Forms.TreeView

	
    Function RotateVector(P As Vector3, x1 As Single, y1 As Single, z1 As Single) As Vector3

        Dim s, c As Double
        Dim y, x, Z As Single
        Dim temp As Vector3

        temp = P

        If x1 <> 0 Then ' Ruta sull'asse x
            s = System.Math.Sin(Rad(x1)) : c = System.Math.Cos(Rad(x1))
            y = c * temp.Y - s * temp.Z
            Z = s * temp.Y + c * temp.Z
            temp.Y = y
            temp.Z = Z
        End If

        If y1 <> 0 Then ' Ruta sull'asse Y
            s = System.Math.Sin(Rad(y1)) : c = System.Math.Cos(Rad(y1))
            y = c * temp.Z - s * temp.X
            Z = s * temp.Z + c * temp.X
            temp.Z = y
            temp.X = Z
        End If

        If z1 <> 0 Then ' Ruta sull'asse z
            s = System.Math.Sin(Rad(z1)) : c = System.Math.Cos(Rad(z1))
            y = c * temp.X - s * temp.Y
            Z = s * temp.X + c * temp.Y
            temp.X = y
            temp.Y = Z
        End If

        Return temp

    End Function
	
	
	Function Rad(ByRef angle As Single) As Single
		Rad = angle * g_pi / 180
	End Function
	
	Function GenHandle() As String
		
		' Restituisce un numero casuale compreso tra
		' -64000000 e 64000000 convertito in esadecimale string
		
		Randomize()
        Return Hex(CInt((64000000 * Rnd()) - 64000000))
		
		
	End Function
	
	Sub InitArrayColors()
		
		AddScheme("White", 1#, 1#, 1#)
		AddScheme("CRed", 1#, 0#, 0#)
		AddScheme("CGreen", 0#, 1#, 0#)
		AddScheme("CBlue", 0#, 0#, 1#)
		AddScheme("Yellow", 1#, 1#, 0#)
		AddScheme("Cyan", 0#, 1#, 1#)
		AddScheme("Magenta", 1#, 0#, 1#)
		AddScheme("Black", 0#, 0#, 0#)
		AddScheme("Aquamarine", 0.439216, 0.858824, 0.576471)
		AddScheme("BlueViolet", 0.62352, 0.372549, 0.623529)
		AddScheme("Brown", 0.647059, 0.164706, 0.164706)
		AddScheme("CadetBlue", 0.372549, 0.623529, 0.623529)
		AddScheme("Coral", 1#, 0.498039, 0#)
		AddScheme("CornflowerBlue", 0.258824, 0.258824, 0.435294)
		AddScheme("DarkGreen", 0.184314, 0.309804, 0.184314)
		AddScheme("DarkOliveGreen", 0.309804, 0.309804, 0.184314)
		AddScheme("DarkOrchid", 0.6, 0.196078, 0.8)
		AddScheme("DarkSlateBlue", 0.419608, 0.137255, 0.556863)
		AddScheme("DarkSlateGray", 0.184314, 0.309804, 0.309804)
		AddScheme("DarkTurquoise", 0.439216, 0.576471, 0.858824)
		AddScheme("DimGray", 0.329412, 0.329412, 0.329412)
		AddScheme("DimGrey", 0.329412, 0.329412, 0.329412)
		AddScheme("Firebrick", 0.556863, 0.137255, 0.137255)
		AddScheme("ForestGreen", 0.137255, 0.556863, 0.137255)
		AddScheme("Gold", 0.8, 0.498039, 0.196078)
		AddScheme("Goldenrod", 0.858824, 0.858824, 0.439216)
		AddScheme("Gray", 0.752941, 0.752941, 0.752941)
		AddScheme("GreenYellow", 0.576471, 0.858824, 0.439216)
		AddScheme("Grey", 0.752941, 0.752941, 0.752941)
		AddScheme("IndianRed", 0.309804, 0.184314, 0.184314)
		AddScheme("Khaki", 0.623529, 0.623529, 0.372549)
		AddScheme("LightBlue", 0.74902, 0.847059, 0.847059)
		AddScheme("LightGray", 0.658824, 0.658824, 0.658824)
		AddScheme("LightSteelBlue", 0.560784, 0.560784, 0.737255)
		AddScheme("LimeGreen", 0.196078, 0.8, 0.196078)
		AddScheme("Maroon", 0.556863, 0.137255, 0.419608)
		AddScheme("MediumAquamarine", 0.196078, 0.8, 0.6)
		AddScheme("MediumBlue", 0.196078, 0.196078, 0.8)
		AddScheme("MediumForestGreen", 0.419608, 0.556863, 0.137255)
		AddScheme("MediumGoldenrod", 0.917647, 0.917647, 0.678431)
		AddScheme("MediumOrchid", 0.576471, 0.439216, 0.858824)
		AddScheme("MediumSeaGreen", 0.258824, 0.435294, 0.258824)
		AddScheme("MediumSlateBlue", 0.498039, 0#, 1#)
		AddScheme("MediumSpringGreen", 0.498039, 1#, 0#)
		AddScheme("MediumTurquoise", 0.439216, 0.858824, 0.858824)
		AddScheme("MediumVioletRed", 0.858824, 0.439216, 0.576471)
		AddScheme("MidnightBlue", 0.184314, 0.184314, 0.309804)
		AddScheme("Navy", 0.137255, 0.137255, 0.556863)
		AddScheme("NavyBlue", 0.137255, 0.137255, 0.556863)
		AddScheme("Orange", 0.8, 0.196078, 0.196078)
		AddScheme("OrangeRed", 1#, 0.498039, 0#)
		AddScheme("Orchid", 0.858824, 0.439216, 0.858824)
		AddScheme("PaleGreen", 0.560784, 0.737255, 0.560784)
		AddScheme("Pink", 0.737255, 0.560784, 0.560784)
		AddScheme("Plum", 0.917647, 0.678431, 0.917647)
		AddScheme("Salmon", 0.435294, 0.258824, 0.258824)
		AddScheme("SeaGreen", 0.137255, 0.556863, 0.419608)
		AddScheme("Sienna", 0.556863, 0.419608, 0.137255)
		AddScheme("SkyBlue", 0.196078, 0.6, 0.8)
		AddScheme("SlateBlue", 0#, 0.498039, 1#)
		AddScheme("SpringGreen", 0#, 1#, 0.498039)
		AddScheme("SteelBlue", 0.137255, 0.419608, 0.556863)
		AddScheme("Tan", 0.858824, 0.576471, 0.439216)
		AddScheme("Thistle", 0.847059, 0.74902, 0.847059)
		AddScheme("Turquoise", 0.678431, 0.917647, 0.917647)
		AddScheme("Violet", 0.309804, 0.184314, 0.309804)
		AddScheme("VioletRed", 0.8, 0.196078, 0.6)
		AddScheme("Wheat", 0.847059, 0.847059, 0.74902)
		AddScheme("YellowGreen", 0.6, 0.8, 0.196078)
		AddScheme("SummerSky", 0.22, 0.69, 0.87)
		AddScheme("RichBlue", 0.35, 0.35, 0.67)
		AddScheme("Brass", 0.71, 0.65, 0.26)
		AddScheme("Copper", 0.72, 0.45, 0.2)
		AddScheme("Bronze", 0.55, 0.47, 0.14)
		AddScheme("Bronze2", 0.65, 0.49, 0.24)
		AddScheme("Silver", 0.9, 0.91, 0.98)
		AddScheme("BrightGold", 0.85, 0.85, 0.1)
		AddScheme("OldGold", 0.81, 0.71, 0.23)
		AddScheme("Feldspar", 0.82, 0.57, 0.46)
		AddScheme("Quartz", 0.85, 0.85, 0.95)
		
	End Sub
	
	Sub AddScheme(ByRef Nome As String, ByRef r As Double, ByRef g As Double, ByRef b As Double)
		
		Dim i As Short
		
		TotalSchemes = TotalSchemes + 1
		ReDim Preserve ColorScheme(TotalSchemes)
		
		i = TotalSchemes
		
		ColorScheme(i).Name = Nome
		ColorScheme(i).r = r
		ColorScheme(i).g = g
		ColorScheme(i).b = b
		
	End Sub
	
    Function Max(v1 As Single, v2 As Single) As Single
        If v1 > v2 Then Return v1 Else Return v2
    End Function
	
    Function Min(v1 As Single, v2 As Single) As Single
        If v1 < v2 Then Return v1 Else Return v2
    End Function
End Module